﻿/*-
 * Liame, the email obfuscator.
 * Copyright (c) 2008 José M. Aguilar
 * http://wwww.variablenotfound.com
 * All rights reserved.
 *
 * Distributed under BSD License.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by José M. Aguilar
 *        and contributors.
 * 4. Neither the name of copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

using System;
namespace Liame.Encoding
{
    /// <summary>
    /// Base class for all codecs
    /// </summary>
    public abstract class LiameCodec
    {
        /// <summary>
        /// Encodes a text.
        /// </summary>
        /// <param name="clearText">Text to be encoded</param>
        /// <returns>The encoded text.</returns>
        /// <remarks>The default implementation returns the clear text</remarks>
        public virtual string Encode(string clearText)
        {
            return clearText;
        }

        /// <summary>
        /// Get the javascript code that calls the decoder. It must return
        /// the decoded text.
        /// For example:
        /// <code>
        ///     function [functionName]()
        ///     {
        ///         return [decoderFunctionName]("text-to-decode");
        ///     }
        /// </code>
        /// </summary>
        /// <param name="functionName">Name of the javascript function you must write</param>
        /// <param name="decoderFunctionName">Name of the javascript function that will decode the text</param>
        /// <param name="clearText">Clear text</param>
        /// <returns>The javascript function</returns>
        /// <remarks>The default implementation returns String.Empty</remarks>
        public virtual string GetDecoderCaller(string functionName, string decoderFunctionName, string clearText)
        {
            return string.Empty;
        }

        /// <summary>
        /// Gets the javascript code that returns the decoded text.
        /// </summary>
        /// <param name="functionName">The function name assigned by Liame</param>
        /// <returns>Javascript code</returns>
        /// <remarks>The default implementation returns String.Empty</remarks>
        public virtual string GetScriptDecoder(string functionName)
        {
            return string.Empty;
        }

        /// <summary>
        /// Get the javascript code that generates the email link
        /// </summary>
        /// <param name="varName">Unique variable name that identifies the Liame instance.</param>
        /// <param name="clearText">Clear text, not encoded</param>
        /// <returns>The javascript code</returns>
        public abstract string GetScriptEmailWriter(string varName, string clearText);
    }
}
